`
Now we can run the aliased command using the name of the alias:
$ quicknmap
Starting Nmap 7.80 ( https://nmap.org ) at 2023-02-21 22:32 EST
--snip--
PORT STATE SERVICE
631/tcp open ipp
You can even assign an alias to your own scripts:
$ alias helloworld="bash ~/scripts/helloworld.sh"
Aliases aren’t permanent, but they can be. In the next section, you’ll learn
how to use bash profiles to make permanent changes to your shell.
Customizing the Bash Run Commands Profile (bashrc)
We can use the ~/.bashrc file to load functions, variables, and just about any
other custom bash code we desire into a new bash session. For example, we can
create variables containing information we’ll frequently need to access, such as the
IP address of a vulnerable host we’re testing.
For example, we could append the following to the end of the ~/.bashrc file.
These lines define a few custom variables and save our aliased Nmap command:
VULN_HOST=1.0.0.22
VULN_ROUTER=10.0.0.254
alias quicknmap="nmap -vv -T4 -p- -sV --max-retries 5 example.local"
The next time you open a terminal, you’ll be able to access these values. Make
these new values available immediately by re-importing the ~/.bashrc file using
the source command:
$ source ~/.bashrc
$ echo $VULN_HOST
10.0.0.22
$ echo $VULN_ROUTER
10.0.0.254
Now you can use these variables even after you close the terminal and start a
new session.
Importing Custom Scripts
Another way to introduce changes to your bash session is to create a dedicated
script that contains pentesting-related customizations and have the ~/.bashrc file
import it using the source command. To achieve this, create a ~/.pentest.sh file
containing your new logic, and then make a one-time modification to ~/.bashrc to
import it at the end of the file:
source ~/.pentest.sh
Black Hat Bash (Early Access) © 2023 by Dolev Farhi and Nick Aleks